home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / cgazv4n2.zip / CPP.ZIP / FILELIST.HXX < prev    next >
Text File  |  1989-08-26  |  3KB  |  95 lines

  1. // FILELIST.HXX
  2. #ifndef _FILELIST_HXX
  3. #define _FILELIST_HXX
  4.  
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include "llist.hxx"
  9.  
  10. // This enumeration shows how to display directory_items.
  11. // You can specify the values in enumerations.  These values 
  12. // are chosen so they each occupy a separate bit position.  That
  13. // way they can just be added together if you want to combine
  14. // several format specifications:
  15. enum display_format { sizes = 0x1, times = 0x2, dates = 0x4, 
  16.                       attributes = 0x8, subdirs = 0x10 };
  17. // (in release 2.0, enumerations can be local to classes.  This
  18. // would have been convenient here).
  19.  
  20. class directory_item {
  21. protected:  // so derived classes have access to this data
  22.   char name[13];
  23.   unsigned long size;
  24.   unsigned time, date;
  25.   char attribute;
  26. public:
  27.   directory_item(FIND * p) {
  28.     strcpy(name, p->name);
  29.     strlwr(name);  // change to lower case
  30.     attribute = p->attribute;
  31.     size = p->size;
  32.     time = p->time;
  33.     date = p->date;
  34.   }
  35.   // The expand() function is only used by subdir.  It is easier
  36.   // to go through the list and tell each element to expand than
  37.   // it is to check to see if each one is a subdir.  Subdir is
  38.   // the only subclass which has a non-empty function body:
  39.   virtual void expand() {}
  40.   // The display() function can take any of the options ORed 
  41.   // (or simply added) together:
  42.   virtual void display(display_format);
  43.   virtual unsigned long bytes() { return size; }
  44. };
  45.  
  46. class file : public directory_item {
  47. public:
  48.   file(FIND * p) : (p) {}
  49.   void display(display_format format);
  50. };
  51.  
  52. class file_list; // name declaration (so it can be used in subdir)
  53.  
  54. class subdir : public directory_item {
  55.   file_list * subdir_list;
  56.   int expanded;  // whether this subdirectory has been expanded
  57.   char pattern[13]; // contains * and ? for matching files
  58.   char * path;  // path name
  59. public:
  60.   subdir(FIND * p, char * afn);
  61.   ~subdir();
  62.   // To find all files in a directory, you must call
  63.   // findnext() until it returns null.  This means that
  64.   // none of the subdirectories can be expanded until the
  65.   // parent directory is complete, so expand() is not part
  66.   // of the constructor.
  67.   void expand();
  68.   void display(display_format format);
  69.   unsigned long bytes();
  70. };
  71.  
  72. class file_list : public llist {
  73. protected:
  74.   void delete_data(void * dn) {
  75.     delete (directory_item *)dn;
  76.   }
  77. public:
  78.   file_list() : () {}  // not necessary; happens automatically
  79.   // Notice how specifying the argument types and return values
  80.   // (instead of using llist's void types) forces the compiler
  81.   // to do strong type checking, but doesn't add any run-time overhead:
  82.   void append(directory_item * el) { llist::append(el); }
  83.   void insert(directory_item * el) { llist::insert(el); }
  84.   directory_item * value() { return (directory_item *)llist::value(); }
  85.   // constructor to create a list of files from an ambiguous
  86.   // file name (afn):
  87.   file_list(char * afn);
  88.   void expand_list();  // expand all subdirectories
  89.   // calculate disk space used by all files:
  90.   unsigned long disk_space(char * msg = "");
  91.   void display_all(display_format format);
  92. };
  93.  
  94. #endif // _FILELIST_HXX
  95.